import org.dreamwork.misc.DefaultSerialNumberSequence;
import org.dreamwork.misc.ISerialNumberSequence;
import org.dreamwork.misc.SerialNumber;
import test.Target;
import test.TestException;

import java.lang.reflect.Method;
import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2014/12/12
 * Time: 22:39
 */
public class ReflectTest {
    public static void main (String[] args) throws Exception {

        System.out.println ("Times\t\tDefault\t\tStatic");
        for (int i = 0; i < 10; i ++) {
            Map<String, Long> map = new HashMap<String, Long> ();
            SerialNumber sn = SerialNumber.newSerialNumber ("DSNS-" + (i), 15, new DefaultSerialNumberSequence ());
            long time1 = test (sn);
            sn = SerialNumber.newSerialNumber ("SFS-" + i, 15, new StaticFieldSequence ());
            long time2 = test (sn);
            System.out.printf ("%d\t\t%d\t\t%d%n", i, time1, time2);
        }
    }

    private static long test (SerialNumber sn) {
        long start = System.currentTimeMillis ();
        for (int i = 0; i < 10000000; i ++)
            sn.next ();
        return System.currentTimeMillis () - start;
    }
}

class TestThread extends Thread {
    private String name;
    Map<String, String> map;
    List<String> list;
    SerialNumber sn;

    public TestThread (String name, Map<String, String> map, List<String> list, SerialNumber sn) {
        this.name = name;
        this.map = map;
        this.list = list;
        this.sn = sn;
    }

    @Override
    public void run () {
        for (int i = 0; i < 1000; i ++) {
/*
            String expression = sn.next ();
            System.err.println ("sn = " + expression);
            map.put (expression, "[" + name + "][" + i + "] sn = " + expression);
            list.add (expression);
*/
            sn.next ();
        }
    }
}

class MyMap<K, V> extends HashMap<K, V> {
    @Override
    public V put (K key, V value) {
        System.out.println ("key = " + key + ", value = " + value);
        return super.put (key, value);
    }
}

class StaticFieldSequence implements ISerialNumberSequence {
    private static long value;

    @Override
    public void set (long value) {
        StaticFieldSequence.value = value;
    }

    @Override
    public long get () {
        return value;
    }

    @Override
    public long next () {
        return value ++;
    }

    @Override
    public void save () {

    }

    @Override
    public void restore () {

    }
}